//
//  HXDGoodsIntroTableViewCell.m
//  qingDaoCircleOfLife
//
//  Created by huxuedong on 15/11/27.
//  Copyright © 2015年 huxuedong. All rights reserved.
//

#import "HXDGoodsIntroTableViewCell.h"

@interface HXDGoodsIntroTableViewCell ()

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *introLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UIButton *shareButton;
@property (weak, nonatomic) IBOutlet UIButton *buyButton;

@end

@implementation HXDGoodsIntroTableViewCell

+ (instancetype)goodsIntroTableViewCell {
    return [[NSBundle mainBundle] loadNibNamed:@"HXDGoodsIntroTableViewCell" owner:nil options:nil].lastObject;
}

- (void)awakeFromNib {
    self.shareButton.layer.cornerRadius = 5;
    self.shareButton.clipsToBounds = YES;
    self.buyButton.layer.cornerRadius = 5;
    self.buyButton.clipsToBounds = YES;
    self.introLabel.numberOfLines = 0;
}

- (void)setGoodsIntro:(HXDGoodsIntroModel *)goodsIntro {
    _goodsIntro = goodsIntro;
    self.titleLabel.text = goodsIntro.title;
    self.introLabel.text = goodsIntro.content;
    self.priceLabel.text = [NSString stringWithFormat:@"人均:￥%@",goodsIntro.price];
    CGSize introSize = [self sizeWithText:goodsIntro.content font:[UIFont systemFontOfSize:13] maxSize:CGSizeMake(359, 95)];
    self.introLabel.frame = CGRectMake(8, 37, introSize.width, introSize.height);
}

//根据给定的字符串及字体，计算字符串的实际大小
- (CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize {
    //设置一个给定字体的各种属性，存放在一个字典集合中（此处只存放了一个字体大小属性的键值对）
    NSDictionary *attribute = @{NSFontAttributeName:font};
    //调用NSString的对象方法，计算text的size
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attribute context:nil].size;
}

@end
